package io.modules.test.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.modules.test.entity.EmpEntity;
import io.modules.test.service.EmpService;
import io.common.utils.PageUtils;
import io.common.utils.R;



/**
 * 员工管理
 *
 * @author jjp
 * @email dark@gmail.com
 * @date 2022-04-10 14:26:43
 */
@RestController
@RequestMapping("test/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("test:emp:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = empService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{empId}")
    @RequiresPermissions("test:emp:info")
    public R info(@PathVariable("empId") Long empId){
		EmpEntity emp = empService.getById(empId);

        return R.ok().put("emp", emp);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("test:emp:save")
    public R save(@RequestBody EmpEntity emp){
		empService.save(emp);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("test:emp:update")
    public R update(@RequestBody EmpEntity emp){
		empService.updateById(emp);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("test:emp:delete")
    public R delete(@RequestBody Long[] empIds){
		empService.removeByIds(Arrays.asList(empIds));

        return R.ok();
    }

}
